﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.actions {
    import flash.geom.*;
    import Classes.*;
    import Classes.util.*;

    public class ActionHarvest extends BaseResourceAction {

        protected var m_harvestResource:HarvestableResource;
        private var m_playOnReenter:Boolean = true;

        public function ActionHarvest(_arg1:NPC, _arg2:HarvestableResource){
            super(_arg1, _arg2);
            this.m_harvestResource = _arg2;
        }
        override public function update(_arg1:Number):void{
            var _local2:Number;
            var _local3:String;
            if (m_actionStarted){
                m_actionTime = (m_actionTime + _arg1);
                _local2 = (m_actionTime / this.m_harvestResource.getHarvestTime());
                if (_local2 > 1){
                    if (this.m_harvestResource.isHarvestable()){
                        this.finalizeHarvest();
                    } else {
                        if (Global.isVisiting()){
                            switch (this.m_harvestResource.getState()){
                                case HarvestableResource.STATE_PLANTED:
                                    this.finalizeWater();
                                    break;
                                case HarvestableResource.STATE_WITHERED:
                                    this.finalizeRevive();
                                    break;
                            };
                        };
                    };
                    m_npc.getStateMachine().removeState(this);
                } else {
                    if (this.m_harvestResource.showActionBar()){
                        _local3 = this.m_harvestResource.getActionText();
                        switch (this.m_harvestResource.getState()){
                            case HarvestableResource.STATE_PLANTED:
                                _local3 = this.m_harvestResource.getWateringText();
                                break;
                            case HarvestableResource.STATE_WITHERED:
                                _local3 = this.m_harvestResource.getRevivingText();
                                break;
                        };
                        this.m_harvestResource.setActionBarOffset(0, (this.m_harvestResource.content.height >> 1));
                        this.m_harvestResource.setActionProgress(true, _local3, _local2, false);
                    };
                };
            };
        }
        protected function finalizeHarvest():void{
            var _local1:Boolean = this.m_harvestResource.harvest();
            if (_local1){
                this.m_harvestResource.doHarvestDropOff();
            };
        }
        protected function finalizeWater():void{
            var _local1:Boolean = this.m_harvestResource.visitBoost();
        }
        protected function finalizeRevive():void{
            var _local1:Boolean = this.m_harvestResource.revive();
        }
        override public function enter():void{
            super.enter();
            if (this.m_actionStarted){
                this.m_playOnReenter = false;
                Sounds.playFromSet(Sounds.SET_HARVEST, this.m_harvestResource);
                m_npc.hideFeedbackBubble();
            };
        }
        override public function reenter():void{
            super.reenter();
            if (((this.m_playOnReenter) && (m_actionStarted))){
                Sounds.playFromSet(Sounds.SET_HARVEST, this.m_harvestResource);
            };
        }
        override public function exit():void{
            this.m_harvestResource.setActionProgress(false);
            this.m_harvestResource.setActionBarOffset(0, 0);
            super.exit();
        }
        override protected function getActionPosition():Point{
            return (null);
        }

    }
}//package Classes.actions 
